package Demo02;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—05—22
 * Time: 10:10
 */
class Money implements Cloneable{
    public double money = 29;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

class person implements Cloneable{
    public int age = 10;
    public Money m = new Money();

    @Override
    protected Object clone() throws CloneNotSupportedException {
        person ret = (person) super.clone();
        ret.m = (Money) this.m.clone();
        return ret;
       // return super.clone();
    }

    @Override
    public String toString() {
        return "person{" +
                "age=" + age +
                '}';
    }
}
public class Test01 {
/*
    public void func() throws CloneNotSupportedException {
        person person = new person();
        person person1 = (person) super.clone();
        System.out.println(person);
        System.out.println(person1);
    }*/

    public static void main(String[] args) throws CloneNotSupportedException {
        person person = new person();
        person person1 = (person) person.clone();
        person1.m.money = 99;
        System.out.println(person.m.money);
        System.out.println(person1.m.money);
    }

/*    public static void main1(String[] args) throws CloneNotSupportedException {
        Test01 test01 = new Test01();
        test01.func();

    }*/
}
